package cn.wsalix.biz.entity;

import javax.persistence.Basic;
import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.EntityListeners;
import javax.persistence.FetchType;
import javax.persistence.ForeignKey;
import javax.persistence.JoinColumn;
import javax.persistence.Lob;
import javax.persistence.ManyToOne;
import javax.persistence.Table;

import lombok.Data;
import lombok.EqualsAndHashCode;

import org.hibernate.annotations.Cache;
import org.hibernate.annotations.CacheConcurrencyStrategy;
import org.hibernate.annotations.DynamicInsert;
import org.hibernate.annotations.DynamicUpdate;
import org.springframework.data.jpa.domain.support.AuditingEntityListener;

import cn.anlaser.entity.CommonEntity;
import cn.wsalix.status.ActEnum;

/**
 * @author jskyme 文章
 */
@Entity
@DynamicInsert
@DynamicUpdate
@Table(name = "ARTICLE")
@Cache(usage = CacheConcurrencyStrategy.READ_WRITE)
@EntityListeners({ AuditingEntityListener.class })
@Data
@EqualsAndHashCode(callSuper = false)
public class Article extends CommonEntity {

	private static final long serialVersionUID = 9027885954610744145L;

	public Article() {
		super();
	}

	public Article(String title, String content) {
		super();
		this.title = title;
		this.content = content;
	}

	/*
	 * @Lob
	 * 
	 * @Basic(fetch = FetchType.LAZY)
	 * 
	 * @Column(name = "intro", columnDefinition = "TEXT", nullable = true,
	 * length = 500) private String intro;
	 */
	private String title; //
	private String source;// 来源
	private ActEnum status;
	//private ArticleEnum type;
	@Lob
	@Basic(fetch = FetchType.LAZY)
	@Column(name = "CONTENT", columnDefinition = "TEXT", nullable = true, length = 100000)
	private String content;
	private String logo;

	private Long creator;// 作者

	@ManyToOne(cascade = CascadeType.MERGE, optional = true, fetch = FetchType.LAZY)
	@JoinColumn(foreignKey = @ForeignKey(name = "FK_ARTICLE_CATEGORY"), name = "CATEGORY_ID")
	private Category category;
}